package cn.springboot.common.http;

import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;

@SuppressWarnings("deprecation")
public class HttpClientPool {

  public static HttpClient httpClient;

  static {
    PoolingClientConnectionManager cm = new PoolingClientConnectionManager();// 创建connectionManager

    cm.setDefaultMaxPerRoute(20);// 对每个指定连接的服务器（指定的ip）可以创建并发20 socket进行访问
    cm.setMaxTotal(100);// 创建socket的上线是200

    httpClient = new DefaultHttpClient(cm);// 使用连接池创建连接
    HttpParams params = httpClient.getParams();
    HttpConnectionParams.setSoTimeout(params, 10 * 1000);// 设定连接等待时间
    HttpConnectionParams.setConnectionTimeout(params, 10 * 1000);// 设定超时时间
  }

  public static void main(String[] args) {

  }

}
